home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
026-050
/
scopedisk32
/
bb1
/
blockbuster.doc
< prev
next >
Wrap
Text File
|
1995-03-18
|
17KB
|
360 lines
Blockbuster Disk Editor
by Ken Turcotte
If you've ever wondered how information is stored on floppy disks
then Blockbuster -- my utility program that lets you examine and
modify 3.5 inch floppy disks at the sector level -- is for you.
Blockbuster is useful for performing operations that the
Amiga's Disk Operating System (DOS) does not support, and for
modifying programs that you otherwise could not change. If you're
familiar with the CLI you'll be right at home with it. Unlike
traditional sector editors, Blockbuster automatically follows
directory paths and moves through files. With its FIND feature you
can search an entire disk for a key word. For example, say you want
to install a program that always looks for a data file on dh0:, your
hard drive. Simply search for df0: on the disk that program is stored
on by clicking on the FIND gadget, and entering df0:. When the proper
occurrence has been found, change the f to h (changing f for Floppy to
h for Hard) and write the modified sector to the disk. That will
provide you with a modified version of the program on floppy; copy it
onto your hard drive and you're off.
Before we go into using Blockbuster however let's start with some
information about the AmigaDOS 1.2 filing system, the vast majority of
which will still be pertinent under the new Workbench 1.3 version that
Commodore, in its inimitable style, has been threatening to ship for
months.
Tracks, Sectors, Cylinders and Blocks
Although this lingo seems more appropriate to racing cars than
computers, the Amiga uses 3.5 inch double- sided floppy disks that are
addressed in this manner. Information is recorded on disks in
concentric circles called tracks.
There are tracks on both the bottom and top surfaces of a disk.
There are also two heads in a disk drive, one for each side of the
disk. These two heads are positioned by a single stepper motor which
means that the heads are always opposite of each other, and the two
opposing tracks make up another unit called a cylinder. Anyone who has
formatted or duplicated a disk has seen the term cylinder before.
Notice that you will hear the heads move each time the cylinder number
changes.
Each track can be broken down further into a unit called a
sector. A sector holds 512 bytes of data. This smaller unit is used
to make the disk more manageable. This 512 byte unit is also known as
a block. There are 11 sectors or blocks on each track; double this
because the disk is double-sided and we have 22 sectors per cylinder.
There is enough room on a disk to hold 80 cylinders. This means
that a disk can hold 1760 sectors. Each sector holds .5 K of data,
for a total storage capacity of 880K. Normally the cylinders are
numbered from 0 to 79 and the sectors on each track are numbered from
0 to 11. Each surface also has it's own number, either 0 or 1. The
upshot of all these numbers is that in order to access any sector on
the disk we must know the cylinder, sector and head number.
To simplify locating data, DOS numbers all of the blocks on disk
from 0 to 1759. This is known as an offset and is passed from DOS to
the trackdisk.device. The trackdisk.device then converts the offset
into a cylinder, sector and head number. This means that DOS does not
have to know any details about the physical layout of the device and
makes it possible for DOS to use the same filing system on another
device such as a hard drive. All that is required is a new device
driver.
But what does DOS DO?
It is the job of the DOS -- remember, that's short for Disk
Operating System -- to organize the blocks on a disk. This means
keeping track of which blocks contain files, and which locks are free
to be used. Commodore has documented five different block types in
the AmigaDOS manual:
1. Root block
2. User directory block
3. File header block
4. Data block
5. File list block.
Each block is broken up into long word fields (4 bytes). The
AmigaDOS manual states that these fields are of the word size. This
is incorrect. Blockbuster can be used to identify these fields by
positioning the cursor on them. A short description of the field will
appear on the lower right side of the screen.
You can identify each block by checking the first and last field
of the block. The first field is called the type, and the last field
is called the secondary type. Data blocks do not have a secondary
type field. The table below shows you how to determine the block
type. Blockbuster will always calculate the block type and display it
on the bottom of the screen below the hex display. Any non-documented
blocks will appear as block type unknown.
Block Type Secondary
File list 1 -3
Root Block 2 1
User Dir 2 2
File Header 2 -3
Data Block 8 none
There are many common long word information fields among the five
documented block types. These fields include the header key, highest
seq, Size, checksum, parent, and creation date. They are located at
the beginning and near the ends of the blocks. It is generally the
center area of the blocks that differ. Blockbuster automatically
identifies which field the cursor is on, all you have to do is move
the cursor keys around. Fields are described in the following
sections.
The Root Block
The root block is the most important block on the disk. There is
only one root block on each disk and it appears on Block $370
(cylinder 40, sector 0 head 0). This positions it in the middle of
disk. It contains the name of the disk, the time and date the disk was
created, the time and date the disk was last written to, a hash table,
and bitmap information.
The disk name is stored as a BCPL string. This means the first
byte of the disk name field contains the length of the name and the
following bytes contain the name itself.
EAlthough two disks may have the same name they will never have
the same creation date and time. It is this fact that is used by
AmigaDOS to distinguish two disks with the same name. If you wish
AmigaDOS to think that two disk are the same, change this time and
date.
The hash table is a list of the entries in the root directory.
It consists of 72 long words. Each long word can be either 0 or the
block number containing an entry. Each entry will be a file header or
a user directory block. Double click on any hash table entry and this
block will be displayed on the screen. Clicking the INTO gadget with
the root block displayed on the screen will display the first entry in
the hash table. Continue by clicking NEXT to move through the entries
of the hash table. This is similar to listing a directory from CLI.
Clicking the DIR B gadget will always return the display to the root
block.
The bitmap information consists of a bitmap flag and 26 entries
for bitmap pages. This is a map of all the blocks on the disk and an
Amiga 3.5 inch floppy will never need more that one bitmap page. It
is used to determine which blocks are free and which are used. The
bitmap flag indicates if the bitmap is currently valid. If this long
word is 0 then the bitmap is not valid. Whenever you insert a disk
with this flag set to zero into a drive, the disk-validator program
from the l directory of the Workbench disk is executed.
Disk-validator tracks down which blocks are used. A new bitmap is
then Cached in computer memory. The next time a file is written to
this disk the bitmap is corrected and the flag is set to a non-zero
value.
Blockbuster displays the bitmap page of a disk when you click the
MAP gadget. It draws a grid to indicate which blocks are free and
which are in use. Free blocks will be white if you have not changed
the system colors in Preferences. To return to where you left, click
on the CLOSE gadget. Optionally you may click on any block on the map
grid and this block will be displayed.
Common Root Block Fields
All times and dates are stored using the standard Amiga date
format. This is three long words indicating the amount of time
elapsed in days, minutes, and tics since January 1, 1978. The
creation time is also included in the user dir block and file header
block. It is located in the same place in all three block types which
makes it easy to locate. The last altered time and date is unique to
the root block.
The header key is a long word field pointing to the block's
header block. The root block has no header, therefore this field will
always be zero. All block types contain a header key field but only
the data block and file list block make use of it.
The highest seq is only used in the data block and file list
block. For all other block types, including the root block, it will
be zero.
The size field of the root block contains the size of the hash
table. This is always 72 long words long. The size field is included
in all five block types but is used for a different purpose in all
cases.
The first data field is used only in the file header and data
blocks. In the root block this will always contain a zero.
The checksum is used to indicate if a block is valid. All five
of the documented block types contain a checksum which is calculated
so that the sum of all of the long words in a block ignoring overflow
equals zero. To check to see if a block is valid, add together all
the long words and the result should be zero. Blockbuster will always
calculate a correct checksum before it writes a sector to disk.
User Directory Block
The user directory block is similar to the root block. There is
one user directory block for each sub- directory on a disk. More
important information is the hash table, creation date, directory
name, comment and parent. The first three of these are identical to
the root block. The comment field is used to store a BCPL string
attached with the CLI command filenote. The parent field contains the
block number of this directory's parent. This may point to a root
block, or another user directory block.
It is interesting to note that if you rename a file or directory
the unused portion of the name field remains untouched. This may be
useful for detecting if a program is an original or a copy.
File Header Block
The file header block contains all the information about a file,
but none of the file's contents. This includes the file name,
creation date and time, size in bytes, protection bits, and file
comment. It also contains a list of all the data blocks used for the
file, the number of data blocks used, and a pointer to the file's
parent directory.
The data block list contains the block numbers of all the data
blocks used. The list starts at the end of the block list field and
works backwards. By double clicking on any entry in the data block
list you can move directly to that data block. It is also possible to
click on the INTO gadget to display the first data block of the file.
Repeatedly clicking on the NEXT gadget moves forward through the data
block. Clicking on the LAST gadget will take you back to the file
header block.
The data block list is used by DOS to locate any position in the
file without having to search through all the data blocks -- and this
gives you random access.
File List Block
The file list block is an extension of the file header block. If
the file contains more blocks than can be listed in the file header
block, then the extension field of the file header will point to a
file list block. The file list block is just a continuation of this
list. For most files there will be no file list block but larger
files may have multiple file list blocks.
Data Block
The data block is used to store the contents of a file. Each
file may have one or multiple data blocks. All data blocks have the
six standard information fields at the beginning.
The header key of the data block contains the block number of the
file header block. Clicking the LAST gadget will display this block.
The sequence number contains the blocks position in the file.
Data size indicates how many data bytes are contained in this
block. Typically this will be 488 bytes. The exception will be when
this is the last data block of the file.
Next data will contain the block number of the next data block in
this file. If the file header block is damaged then this field can be
used to paste the file back together. If this is the last data block
this field will contain a zero.
The data field is 488 bytes long. If the value in data size is
less than 488, then part of the data field will contain garbage. When
file copy is used to duplicate a file the unused portion of the last
data block is not duplicated.
Undocumented blocks
The Amiga filing system has two block types not documented in the
AmigaDOS manual. These are the boot block and the bitmap block.
The boot block is actually two reserved blocks. Blocks 0 and 1
have been set aside for this purpose. The first four bytes of block
zero are used to indicate if the disk is a DOS disk. They will
normally contain the letters 'DOS' followed by a zero.
Normally when you use the CLI command INSTALL a small program
called a bootstrap is written to these two sectors. When the Amiga is
powering up, block zero is checked to see if it contains this
bootstrap. If the bootstrap exists it is loaded into memory and
executed. This program will usually carry out the normal startup-
sequence found in the s directory on Workbench disks. Some commercial
programs contain a custom bootstrap program. These programs usually
take over complete control of the Amiga hardware.
Recently, a third type of boot block has emerged. This is called
a virus. I've came across three different viruses, however have heard
rumors of as many as five. Blockbuster can be used to detect viruses by
inserting a disk and clicking on the BOOT B gadget.
This will display the boot block on the screen. A normal boot block will
contain the word dos.library near the top of the block. If it isn't there
you know that this is not the standard boot block. Examine the ASCII
display of the block or suspicious messages like "virus by byte bandit"
or "something wonderful has happened to your Amiga." Remember to check
block 1 as well. To move to block 1 click on the sector advance gadget.
The SCA virus puts it's messages on block 1.
One way to remove some viruses is to use the INSTALL command from
the CLI. Buy remember that if you booted from that disk, the virus
will be in memory and may reinstall itself as soon as it is removed.
The other undocumented block is the bitmap page. A pointer to
the bitmap page can be found in the root block. Double click on the
bitmap page entry and it will be displayed. Unlike the other
documented block types which have the checksum as the 6th long word of
the block, the bitmap block has the checksum as the first long word.
This means that if you want to modify the bitmap page using
-Blockbuster you must manually calculate a checksum.
Each block on the disk has one bit in the bitmap. When a disk is
formatted most of the bits will be set to 1 indicating that the block
is free. The blocks that will be allocated are the bitmap, root block
and two boot blocks. There may also be blocks allocated for
Workbench-related files depending on how you formatted the disk. The
easiest way to make any sense of the bitmap is to click on the MAP
gadget.
Tricks with the Filing System
It is possible to do many things with the filing system. One
example of this is recovering accidentally deleted files. The easiest
way is to use the DOSKDOCTOR program provided on Workbench which
locates all the file headers and builds new directories.
The primary problem with this method is keeping other programs
from making changes on the disk before the file is recovered. DOS
will occasionally move the bitmap page onto a deleted file, or
Workbench will rewrite its .info files. Trying to recover files when
more than one file has been deleted is easier. Usually you can
recover all of the files but one.
BLOCKBUSTER Command Summary
Gadgets
FIND - Searches for a string from current block.
NEXT - Moves to next file in hash table, or data block
LAST - Moves to file header or parent directory.
INTO - Moves into directory or file.
BOOTB - Moves to the boot block.
DIR B - Moves to the root block.
END B - moves to the last cylinder of the disk.
SECT - Change sector.
CLY - Change cylinder.
H - Toggle drive head. (0 / 1)
D - Toggle drive number. (df0: / df1:)
Keyboard
X - Exits program
HEX - 0-F on main keyboard used to edit block
CURSOR - Moves both hex and ascii cursors.
Menu
WRITE/SECTOR - Writes current block to disk.